var windowName = "pub";
var Page ,LiveList,listService
apiready = function(){
    onWindowHide(function () {
    })
    console.log("index page is OK");
    listService = new List();
    Page = createVM("#Page",{
        //页面数据
        banner:[
            picBanner,
            picBanner,
            picBanner,
            picBanner,
            picBanner,
        ],
        curTab:0,
        distanceOpen:false,
        timeOpen:false,
        sortOpen:false,
        serviceList:[],
        announce:[],
        status:{
            login:1
        }
    },{
        //页面方法
        "init":function () {
            var data =getData4Page()
            console.log(data.text);

            var lat = getLocData("lat");
            var lon = getLocData("lon");
            //推荐服务
            listService = new List()
            listService.setData({lat:lat,lon:lon}).setUrl("/app/product/list").setCbFunc(function (res) {
                clearLoading()
                logJson(res,"listService_")
                Page.serviceList = res
            }).getList();
            //违规通报
            //佣金announce
            var announce = getLocData("announce_pub");if (isTrue(announce))Page.announce = announce;
            logJson(announce,"announce_pub")
            apiGet("/app/announce",{event:[4]},function (res,code) {
                logJson(res,"announce_")
                if (code == 200) {
                    Page.announce = res.data;
                    setLocData("announce_pub",Page.announce);
                }
            })

        }
        ,tab:function (index) {
            log(index)
            Page.curTab = index
        }
        , openShop: function () {
            apiPost("/app/open/shop",{},function (res,code) {
                if (code == 200) {
                    showToast(res.message)

                    //更新用户状态
                    checkUserStatus(function (data) {
                        logJson(data)
                        Page.status = data;
                    })
                }

            })
        }
    })

    Page.init()

    onPullUpLoadMore(function () {
        if ( !isTrue(Page.curTab) ) {
            listService.getList();
        }else {
            clearLoading();
        }
    })
}
function updateWinData() {
    // checkLocalData()
    // startPullUpLoadMore()
    // LiveList.setData({grade:Page.gradeId,subject:Page.subjectId}).reload();
    // if (!isTrue(Page.gradeId)) {
    //     goto("userSetGrade")
    // }
    var announce = getLocData("announce");if (isTrue(announce))Page.announce = announce;
    logJson(announce,"test_announce")
    apiGet("/app/announce",{event:[4]},function (res,code) {
        logJson(res,"announce_")
        if (code == 200) {
            Page.announce = res.data;
            setLocData("announce",Page.announce);
        }
    })

    //更新用户状态
    checkUserStatus(function (data) {
        logJson(data)
        Page.status = data;
    })

}
